//
//  YZDetailsOfDisease.m
//  名医通
//
//  Created by WGP on 16/5/3.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "YZDetailsOfDisease.h"
#import "YZDiseaseChoseView.h"
#import "DiseaseTypeViewController.h"
#import "YZComplicationsViewController.h"
#import "UIColor+YMHex.h"
#import "YZDiseaseTypeModel.h"
#import "YZComplicationModel.h"
#import "YZTwoBtnView.h"
#import "YZBottomView.h"
#import "YZMethodTableVC.h"
#import "YZDoctorTableView.h"
#import <Masonry.h>
#import <SVProgressHUD.h>

@interface YZDetailsOfDisease ()<YZDiseaseChoseViewDelegate,YZTwoBtnViewDelegate>

@property(nonatomic,assign)NSInteger ci1_id;
@property (strong, nonatomic)UILabel *diseaseTypeLabel;
@property(nonatomic,nonnull)NSString *diseaseTypeStr;
@property(nonatomic,strong)YZDiseaseChoseView *diseaseChoseView;
@property(nonatomic,strong)YZDiseaseChoseView *diseaseComplicationsView;
@property(nonatomic,strong)YZDiseaseChoseView *methodView;
@property(nonatomic,strong)YZDiseaseTypeModel *model;
@property(nonatomic,strong)YZComplicationModel *complicationModel;
@property(nonatomic,strong)NSArray <YZComplicationModel *>* array;

@end

@implementation YZDetailsOfDisease


+(instancetype)detailOfDiseaseVCWithId:(NSInteger)cl1_id
{

    YZDetailsOfDisease *vc = [[YZDetailsOfDisease alloc] init];
    vc.ci1_id = cl1_id;
    NSString *diseaseTypeStr = nil;
    switch (cl1_id) {
        case 1:
            diseaseTypeStr = @"疾病类型:肿瘤";
            break;
        case 2:
            diseaseTypeStr = @"疾病类型:心血病";
            break;
        case 3:
            diseaseTypeStr = @"疾病类型:神经科";
            break;
        case 4:
            diseaseTypeStr = @"疾病类型:血液病";
            break;
        case 5:
            diseaseTypeStr = @"疾病类型:骨科";
            break;
        default:
            break;
    }
    vc.diseaseTypeStr = diseaseTypeStr;
    return vc;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"疾病详情选择";
    self.view.backgroundColor = RGB_COLOR(242, 242, 242);
    
    self.navigationController.navigationBar.titleTextAttributes =
   @{
    NSForegroundColorAttributeName:[UIColor whiteColor]
    };
    
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    [self setupUI];
    
}

-(void)setupUI
{
    self.diseaseTypeLabel = [[UILabel alloc] init];
    self.diseaseTypeLabel.text = self.diseaseTypeStr;
    [self.view addSubview:self.diseaseTypeLabel];
    
    YZDiseaseChoseView *diseaseChoseView = [YZDiseaseChoseView diseaseChoseViewWith:@"请选择疾病细分"];
    diseaseChoseView.delegate = self;
    self.diseaseChoseView = diseaseChoseView;
    [self.view addSubview:diseaseChoseView];
    
    YZDiseaseChoseView *diseaseComplicationsView = [YZDiseaseChoseView diseaseChoseViewWith:@"请选择并发症(可多选)"];
    diseaseComplicationsView.delegate = self;
    self.diseaseComplicationsView = diseaseComplicationsView;
    [self.view addSubview:diseaseComplicationsView];
    
    YZTwoBtnView *firstTwoBtnView = [YZTwoBtnView twoBtnViewWith:@"是否确诊" firstBtnTitle:@"症状疑似" secondBtnTitle:@"已确诊" defaultSelected:YZSelectedBtnTypeLeft];
    [self.view addSubview:firstTwoBtnView];
    
    
    YZTwoBtnView *secondTwoBtnView = [YZTwoBtnView twoBtnViewWith:@"是否接受过治疗" firstBtnTitle:@"未接受过" secondBtnTitle:@"接受过" defaultSelected:YZSelectedBtnTypeRight];
    secondTwoBtnView.delegate = self;
    [self.view addSubview:secondTwoBtnView];
    
    YZDiseaseChoseView *methodView = [YZDiseaseChoseView diseaseChoseViewWith:@"请选择治疗方式"];
    methodView.hidden = YES;
    self.methodView = methodView;
    self.methodView.delegate = self;
    [self.view addSubview:methodView];
    
    YZBottomView *bottomView = [YZBottomView bottomView];
    bottomView.bottomBtnDidClickBlock = ^
    {
        if (self.model == nil) {
             [SVProgressHUD setMinimumDismissTimeInterval:1.5];
            [SVProgressHUD showInfoWithStatus:@"请选择疾病细分"];
            return ;
        }
        YZDoctorTableView *doctor = [[YZDoctorTableView alloc] init];
        [self.navigationController pushViewController:doctor animated:YES];
    };
    [self.view addSubview:bottomView];
    
    
    [self.diseaseTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(18+64);
        make.left.equalTo(self.view).offset(12);
    }];
    
    [diseaseChoseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.diseaseTypeLabel).offset(44);
        make.left.equalTo(self.view).offset(12);
        make.right.equalTo(self.view).offset(-12);
        make.height.mas_equalTo(44);
    }];
    
    [diseaseComplicationsView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(diseaseChoseView.mas_bottom).offset(12);
        make.left.right.equalTo(diseaseChoseView);
        make.height.mas_equalTo(44);
    }];
    
    [firstTwoBtnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(diseaseComplicationsView.mas_bottom).offset(12);
        make.left.right.equalTo(diseaseComplicationsView);
        make.height.mas_equalTo(44);
    }];
    
    [secondTwoBtnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(firstTwoBtnView);
        make.top.equalTo(firstTwoBtnView.mas_bottom).offset(12);
        make.height.mas_equalTo(44);
    }];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.view);
        make.height.mas_equalTo(240);
    }];
    
    [methodView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(secondTwoBtnView);
        make.top.equalTo(secondTwoBtnView.mas_bottom).offset(12);
        make.height.mas_equalTo(44);
    }];
}

-(void)diseaseChoseViewWith:(UIView *)diseaseChoseView
{
    if (diseaseChoseView == self.diseaseChoseView) {
        DiseaseTypeViewController *diseaseTypeVC = [[DiseaseTypeViewController alloc] init];
        
        diseaseTypeVC.diseaseTypeBlock = ^(YZDiseaseTypeModel *model)
        {
            self.model = model;
            self.diseaseChoseView.diseaseTypeLabel.text = model.ci3_name;
            self.diseaseChoseView.diseaseTypeLabel.textColor = [UIColor blackColor];
        };
        diseaseTypeVC.ci1_id = self.ci1_id;
        [self.navigationController pushViewController:diseaseTypeVC animated:YES];
    }else if (diseaseChoseView == self.diseaseComplicationsView)
    {
        if (self.model == nil) {
            [SVProgressHUD setMinimumDismissTimeInterval:1.5];
            [SVProgressHUD showInfoWithStatus:@"请选择疾病细分"];
            return ;
        }
        
        YZComplicationsViewController *complicationsVC = [[YZComplicationsViewController alloc] init];
        
        complicationsVC.complicationModelBlock = ^(NSAttributedString *str,NSArray *complicationModelArr)
        {
            self.diseaseComplicationsView.diseaseTypeLabel.textColor = [UIColor blackColor];
            self.diseaseComplicationsView.diseaseTypeLabel.attributedText = str;
            self.array = complicationModelArr;
        };
        
        complicationsVC.ci1_id = self.ci1_id;
        complicationsVC.diseastType = self.model;
        complicationsVC.models = [NSMutableArray arrayWithArray:self.array];
        [self.navigationController pushViewController:complicationsVC animated:YES];
    }
    else if (diseaseChoseView == self.methodView)
    {
        YZMethodTableVC *methodVC = [[YZMethodTableVC alloc] init];
        methodVC.methodBlock = ^(NSString *method)
        {
            self.methodView.diseaseTypeLabel.text =method;
            self.methodView.diseaseTypeLabel.textColor = [UIColor blackColor];
        };
        [self.navigationController pushViewController:methodVC animated:YES];
    }
}

-(void)isHiddenMethodViewWith:(YZTwoBtnView *)twoBtnView
{
    if (twoBtnView.currentSelectedBtn == twoBtnView.secondBtn) {
        self.methodView.hidden = NO;
        self.methodView.diseaseTypeLabel.text = @"请选择治疗方式";
        self.methodView.diseaseTypeLabel.textColor = [UIColor lightGrayColor];
    }else
    {
        self.methodView.hidden = YES;
    }
}

@end
















